package com.fengycx.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONString;
import cn.hutool.json.JSONUtil;
import com.fengycx.constants.Constants;
import org.apache.commons.lang3.StringUtils;
import org.apache.tomcat.util.bcel.Const;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

public class StpInterfaceImpl implements StpInterface {


    private RedisTemplate redisTemplate;

    public StpInterfaceImpl(RedisTemplate redisTemplate) {
        this.redisTemplate=redisTemplate;
    }

    @Override
    public List<String> getPermissionList(Object loginId, String LoginType) {
        Object permissions = redisTemplate.opsForValue().get(String.format(Constants.Redis.LOGIN_INFO_PERMISSIONS, loginId));
        if (ObjectUtil.isNull(permissions)){
            return new ArrayList<>();
        }

        List<String> permissionList = JSONUtil.toList(JSONUtil.parseArray(permissions), String.class);

        return permissionList;
    }


    @Override
    public List<String> getRoleList(Object o, String s) {

        return new ArrayList<>();
    }
}
